import { BasicColumn, BasicTable, FormSchema, useRender, useTable } from "@/components/Table";
import { useTranslation } from "react-i18next";
import { message } from "antd";
import Toolbar from "@/components/ViewComponents/Toolbar";
import { patientOrdersPage } from "@/api/MedicalExamination/index";

const index = () => {
	const { t } = useTranslation();
	const searchFormSchema: FormSchema[] = [
		{
			label: t("kevin_ui.date"),
			field: "1",
			component: "DatePicker"
		},
		{
			label: t("kevin_ui.department"),
			field: "2",
			component: "Input"
		},
		{
			label: t("kevin_ui.patient"),
			field: "3",
			component: "Select",
			componentProps: {
				options: [
					{ label: "Option 1", value: 1 },
					{ label: "Option 2", value: 2 }
				]
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t("felix_ui.patient_ID"),
			dataIndex: "patientId"
		},
		{
			title: t("felix_ui.orderType"),
			dataIndex: "orderType",
			render: value => useRender.renderDictText(value, "order_type")
		},
		{
			title: t("felix_ui.orderAmount"),
			dataIndex: "totalPrice"
		},
		{
			title: t("felix_ui.doctorName"),
			dataIndex: "doctorName"
		},
		{
			title: t("felix_ui.status"),
			dataIndex: "status",
			render: value => useRender.renderDict(value, "order_status")
		}
	];
	const [registerTable, { getSelectRowKeys }] = useTable({
		api: patientOrdersPage,
		columns,
		formConfig: {
			labelWidth: 120,
			schemas: searchFormSchema,
			showActionButtonGroup: true,
			showAdvancedButton: false
		},
		useSearchForm: true,
		rowSelection: { type: "checkbox" }
	});

	/** Function */

	const handlerAction = (key: string) => {
		switch (key) {
			case "print":
				if (!getSelectRowKeys().length) {
					message.warning("Please select at least one record !");
					return;
				}
				message.warning("Print function is not open，please wait~");
				break;
		}
	};

	return (
		<div className="page">
			<div className="page-content block">
				<BasicTable register={registerTable}></BasicTable>
			</div>
			<Toolbar btnList={["print"]} action={handlerAction} />
		</div>
	);
};
export default index;
